<?php

declare(strict_types=1);

use Phinx\Seed\AbstractSeed;

class FileUploadConfigSeeder extends AbstractSeed
{
    /**
     * Run Method.
     */
    public function run(): void
    {
        $table = $this->table('file_upload_config');
        if (!$table->exists()) {
            return;
        }
        // 检查是否已存在数据
        $count = $this->fetchRow("SELECT COUNT(*) as count FROM file_upload_config")['count'];
        if ($count > 0) {
            echo "文件配置表已有数据，跳过填充\n";
            return;
        }
        $rows = [
            [
                'name' => '本地存储',
                'storage_type' => 'local',
                'config' => json_encode([
                    'dirname' => 'storage',
                    'domain' => '',
                    'uri' => '',
                    'algo' => 'sha1',
                ]),
                'single_limit' => 1024 * 1024 * 200, // 200MB
                'total_limit' => 1024 * 1024 * 200,  // 200MB
                'nums' => 10,
                'include' => null,
                'exclude' => null,
                'remark' => '本地文件存储配置',
                'status' => 1,
                'sort' => 0,
                'create_time' => date('Y-m-d H:i:s'),
                'update_time' => date('Y-m-d H:i:s'),
            ],
            [
                'name' => '阿里云OSS',
                'storage_type' => 'oss',
                'config' => json_encode([
                    'accessKeyId' => '',
                    'accessKeySecret' => '',
                    'bucket' => '',
                    'dirname' => 'storage',
                    'domain' => '',
                    'endpoint' => 'oss-cn-hangzhou.aliyuncs.com',
                    'algo' => 'sha1',
                ]),
                'single_limit' => 1024 * 1024 * 200, // 200MB
                'total_limit' => 1024 * 1024 * 200,  // 200MB
                'nums' => 10,
                'include' => null,
                'exclude' => null,
                'remark' => '阿里云对象存储服务',
                'status' => 0,
                'sort' => 1,
                'create_time' => date('Y-m-d H:i:s'),
                'update_time' => date('Y-m-d H:i:s'),
            ],
            [
                'name' => '腾讯云COS',
                'storage_type' => 'cos',
                'config' => json_encode([
                    'secretId' => '',
                    'secretKey' => '',
                    'bucket' => '',
                    'dirname' => 'storage',
                    'domain' => '',
                    'region' => 'ap-shanghai',
                ]),
                'single_limit' => 1024 * 1024 * 200, // 200MB
                'total_limit' => 1024 * 1024 * 200,  // 200MB
                'nums' => 10,
                'include' => null,
                'exclude' => null,
                'remark' => '腾讯云对象存储服务',
                'status' => 0,
                'sort' => 2,
                'create_time' => date('Y-m-d H:i:s'),
                'update_time' => date('Y-m-d H:i:s'),
            ],
            [
                'name' => '七牛云存储',
                'storage_type' => 'qiniu',
                'config' => json_encode([
                    'accessKey' => '',
                    'secretKey' => '',
                    'bucket' => '',
                    'dirname' => 'storage',
                    'domain' => '',
                ]),
                'single_limit' => 1024 * 1024 * 200, // 200MB
                'total_limit' => 1024 * 1024 * 200,  // 200MB
                'nums' => 10,
                'include' => null,
                'exclude' => null,
                'remark' => '七牛云对象存储服务',
                'status' => 0,
                'sort' => 3,
                'create_time' => date('Y-m-d H:i:s'),
                'update_time' => date('Y-m-d H:i:s'),
            ],
            [
                'name' => '亚马逊S3',
                'storage_type' => 's3',
                'config' => json_encode([
                    'key' => '',
                    'secret' => '',
                    'bucket' => '',
                    'dirname' => 'storage',
                    'domain' => '',
                    'region' => 'us-east-1',
                    'version' => 'latest',
                    'use_path_style_endpoint' => true,
                    'endpoint' => '',
                    'acl' => 'public-read',
                ]),
                'single_limit' => 1024 * 1024 * 200, // 200MB
                'total_limit' => 1024 * 1024 * 200,  // 200MB
                'nums' => 10,
                'include' => null,
                'exclude' => null,
                'remark' => '亚马逊S3对象存储服务',
                'status' => 0,
                'sort' => 4,
                'create_time' => date('Y-m-d H:i:s'),
                'update_time' => date('Y-m-d H:i:s'),
            ],
        ];
        $table->insert($rows)->saveData();
        echo "文件配置表数据填充完成\n";
    }
}